<template>
    <div>
        <h-section title="研发流程信息" collapse>
            <flexbox class="cell-item">
                <div class="cell-item-label">当前阶段：</div>
                <div class="font-w-b">{{ stage }}</div>
            </flexbox>
            <common-test-file ref="commonTestFileRef" :detail="detail" :stage="stage" :stepStatus="stepStatus" :disabled="disabled" @detailChange="detailChange" />
            <slot name="processHistoryRecord" />
        </h-section>
    </div>
</template>

<script lang="ts">
import CommonTestFile from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/components/CommonTestFile.vue';
import { defineComponent, ref, unref } from 'vue';
export default defineComponent({
    name: 'BasicLine',
    components: {
        CommonTestFile
    },
    props: {
        detail: {
            type: Object,
            default: () => ({})
        },
        disabled: { type: Boolean, default: false },
        stage: { type: String, default: '' },
        stepStatus: {
            type: String,
            default: ''
        }
    },
    emits: ['save', 'detailChange'],
    setup(props, { emit }) {
        const commonTestFileRef = ref<any>();
        // 验证
        const handleValidate = () => {
            return new Promise((res) => {
                unref(unref(commonTestFileRef).ruleFormRef)
                    .validate()
                    .then(
                        () => {
                            res(true);
                        },
                        () => {
                            res(false);
                        }
                    );
            });
        };
        const handleSave = async (type: number) => {
            let res: any = true;
            const { id, instanceId } = props.detail;
            const query = {
                id,
                instanceId,
                ...unref(commonTestFileRef).form
            };
            if (unref(commonTestFileRef).ruleFormRef) {
                res = await handleValidate();
            }
            if (res) {
                emit('save', {
                    type,
                    query
                });
            }
        };
        const detailChange = () => {
            handleSave(9);
        };
        return {
            commonTestFileRef,
            handleValidate,
            handleSave,
            detailChange
        };
    }
});
</script>

<style scoped lang="less">
@import './styles/index.less';
</style>